package com.biz.primus.ms.tms.api;

import com.biz.primus.model.tms.vo.UpgradeAddReqVo;
import com.biz.primus.model.tms.vo.UpgradeDetailVo;
import com.biz.primus.model.tms.vo.UpgradeRespVo;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.tms.service.UpgradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * UpgradeApiController
 *
 * @author JKLiues
 * @date 2017年11月27日
 */
@Api("配送APP版本控制")
@RestController
@RequestMapping("soa/upgradeService")
public class UpgradeApiController extends BaseApiController {

    @Autowired
    private UpgradeService upgradeService;

    @ApiOperation("版本更新")
    @GetMapping("needUpgrade")
    public UpgradeRespVo needUpgrade(@ApiParam(value = "系统") @RequestParam("os") String os,
                                     @ApiParam(value = "版本号") @RequestParam("version") String version) {
        return upgradeService.needUpgrade(os, version);
    }

    @ApiOperation("获取全部的版本配置")
    @GetMapping("findAll")
    public List<UpgradeDetailVo> findAll() {
        return upgradeService.findAll();
    }

    @ApiOperation("通过系统查版本")
    @GetMapping("findByOs")
    public List<UpgradeDetailVo> findByOs(@ApiParam(value = "系统") @RequestParam("os") String os) {
        return upgradeService.findByOs(os);
    }

    @ApiOperation("禁用版本配置")
    @PostMapping("disable")
    public void disable(@ApiParam(value = "版本配置ID") @RequestParam("id") Long id) {
        upgradeService.disable(id);
    }

    @ApiOperation("添加版本配置")
    @PostMapping("save")
    public void save(@RequestBody UpgradeAddReqVo upgrade) {
        upgradeService.save(upgrade);
    }
}